import 'package:flutter/material.dart';
import 'package:qqmusic/widget/tabrviewModel.dart';

class detailModel extends StatefulWidget {
  detailModel({Key key, this.item}) : super(key: key);
  List item;
  List<Widget> tabs = [];
  List<Widget> tabviews = [];
  @override
  State<detailModel> createState() => _detailModelState();
}

class _detailModelState extends State<detailModel>
    with TickerProviderStateMixin, AutomaticKeepAliveClientMixin {
  TabController controller;
  @override
  void initState() {
    super.initState();
    controller =
        TabController(length: widget.item.length, vsync: this, initialIndex: 0);
    if (widget.tabs.isEmpty) {
      for (var item in widget.item) {
        print(item);
        widget.tabs.add(Text(item));
        widget.tabviews.add(tabarviewModel(
          keys: item,
        ));
      }
      setState(() {});
    }
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.only(
        top: 15,
      ),
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          Container(
            alignment: Alignment.topLeft,
            margin: EdgeInsets.only(bottom: 10),
            child: Theme(
              data: ThemeData(
                  splashColor: Colors.transparent,
                  highlightColor: Colors.transparent),
              child: TabBar(
                tabs: widget.tabs,
                isScrollable: true,
                controller: controller,
                labelColor: Color(0xff242525),
                labelStyle:
                    TextStyle(fontSize: 16, fontWeight: FontWeight.w700),
                unselectedLabelColor: Color(0xffadadad),
                indicator: BoxDecoration(),
                unselectedLabelStyle: TextStyle(),
              ),
            ),
          ),
          Expanded(
              child: TabBarView(
            controller: controller,
            physics: NeverScrollableScrollPhysics(),
            children: widget.tabviews,
          ))
        ],
      ),
    );
  }

  @override
  // TODO: implement wantKeepAlive
  bool get wantKeepAlive => true;
}
